package Practica;

import java_cup.runtime.*;

%%


%{
  public void imprime(String str){
    System.out.println(str + " FILA: " + yyline + " COL: " + yycolumn);
  }
%}

%class Scanner

%unicode
%cup 
%line 
%column

/* String  = \"[^\"]*\"  */

program = "program"
consts = "consts"
const = "const"
vars = "vars"
var = "var"
tipos = "tipos"
tipo = "tipo"
subprograms = "subprograms"
subprogram = "subprogram"
instructions = "instructions"

boolean = "boolean"
character = "character"
natural = "natural"
integer = "integer"
float = "float"

and     = "and"
or      = "or"
in 		= "in"
out 	= "out"
if      = "if"
then    = "then"
else    = "else"
endif   = "endif"
while 	= "while"
do		= "do"
endwhile = "endwhile"

true    = "true"
false   = "false"

identificador = [a-z][a-zA-Z0-9]*

vBoolean = [true | false]
vNatural = 0 | [1-9][0-9]*
vInteger = ("-")? vNatural
vFloat = vInteger [decimal | parteExp | decimal parteExp]
parteExp = "E" vInteger
decimal = "." ( 0 | [0-9]* ([1-9] | [1-9] 0))


%%


[\t\r\n ] {}
#[^\n]*   {}

{program} {imprime("program"); return new Symbol(sym.PROGRAM);}
{consts} {imprime("consts"); return new Symbol(sym.CONSTS);}
{const} {imprime("const"); return new Symbol(sym.CONST);}
{vars} {imprime("vars"); return new Symbol(sym.VARS);}
{var} {imprime("var"); return new Symbol(sym.VAR);}
{tipos} {imprime("tipos"); return new Symbol(sym.TIPOS);}
{tipo} {imprime("tipo"); return new Symbol(sym.TIPO);}
{subprograms} {imprime("subprograms"); return new Symbol(sym.SUBPROGRAMS);}
{subprogram} {imprime("subprogram"); return new Symbol(sym.SUBPROGRAM);}
{instructions} {imprime("instructions"); return new Symbol(sym.INSTRUCTIONS);}

{boolean} {return new Symbol(sym.BOOLEAN);}
{character} {return new Symbol(sym.CHARACTER);}
{natural} {return new Symbol(sym.NATURAL);}
{integer} {return new Symbol(sym.INTEGER);}
{float} {return new Symbol(sym.FLOAT);}

{and} {return new Symbol(sym.AND);}
{or} {return new Symbol(sym.OR);}
{in} {return new Symbol(sym.IN);}
{out} {return new Symbol(sym.OUT);}
{if} {return new Symbol(sym.IF);}
{then} {return new Symbol(sym.THEN);}
{else} {return new Symbol(sym.ELSE);}
{endif} {return new Symbol(sym.ENDIF);}
{while} {return new Symbol(sym.WHILE);}
{do} {return new Symbol(sym.DO);}
{while} {return new Symbol(sym.WHILE);}
{endwhile} {return new Symbol(sym.ENDWHILE);}
{true} {return new Symbol(sym.TRUE);}
{false} {return new Symbol(sym.FALSE);}

{identificador} = {return new Symbol(sym.IDENTIFICADOR, yytext());}
{vBoolean} = {return new Symbol(sym.VBOOLEAN);}
{vNatural} = {return new Symbol(sym.VNATURAL);}
{vInteger} = {return new Symbol(sym.VINTEGER);}
{vFloat} = {return new Symbol(sym.VFLOAT);}

\(      {return new Symbol(sym.PAP);}
\)      {return new Symbol(sym.PCIERRE);}
\:      {return new Symbol(sym.DOSP);}
\;      {return new Symbol(sym.PCOMA); }
\{      {return new Symbol(sym.LLAVEAP);}
\}      {return new Symbol(sym.LLAVECIERRE);}
\[      {return new Symbol(sym.CORCHAP);}
\]      {return new Symbol(sym.CORCHCIERRE); }
\'      {return new Symbol(sym.COMILLA); }

[^]       {throw new Error("Caracter no reconocido:"+yytext());}


